package com.zhangyue.wqercs.guideactivity;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    int[] layouts = {R.layout.guide1_fragment,R.layout.guide2_fragment,R.layout.guide3_fragment};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ViewPager vp = findViewById(R.id.viewpager);
        vp.setAdapter(new MyAdapter(getSupportFragmentManager()));
        MyPageTransformer pageTransformer = new MyPageTransformer();

        vp.setPageTransformer(true,pageTransformer);
        vp.addOnPageChangeListener(pageTransformer);
    }
    class MyAdapter extends FragmentPagerAdapter {
        public MyAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int i) {
            TranslateFragment translateFragment = new TranslateFragment();
            Bundle b = new Bundle();
            b.putInt("index",i);
            b.putInt("resId",layouts[i]);
            translateFragment.setArguments(b);
            return translateFragment;
        }

        @Override
        public int getCount() {
            return layouts.length;
        }
    }
}
